<?php
/**
 * Created by PhpStorm.
 * User: charles
 * Date: 2017-11-19
 * Time: 15:54
 */

namespace App\Http\Controllers\LA;


use App\Http\Controllers\Controller;
use App\Models\Member;
use Illuminate\Http\Request;

class WechatMemberController extends Controller
{
    public function index(Request $request)
    {
        $query = Member::query();
        if (strlen((string) $request->openid)) {
            $query->where('openid', $request->openid);
        }
        if (strlen((string) $request->nickname)) {
            $query->where('nickname', 'like', "%{$request->nickname}%");
        }
        $members = $query
            ->orderBy('id', 'desc')
            ->paginate(20);
        return view('la.wechat-members.index', compact('members'));
    }

    public function enableHotVideo(Request $request)
    {
        $member = Member::findOrFail($request->id);
        $member->hot_video = 1;
        $member->save();
        return redirect()->back();
    }

    public function disableHotVideo(Request $request)
    {
        $member = Member::findOrFail($request->id);
        $member->hot_video = 0;
        $member->save();
        return redirect()->back();
    }

    public function show($id)
    {
        $member = Member::findOrFail($id);
        return view('la.wechat-members.show', compact('member'));
    }

    public function update($id, Request $request)
    {
        $member = Member::findOrFail($id);
        $member->alipay_account = $request->alipay_account;
        $member->alipay_name = $request->alipay_name;
        $member->save();
        return redirect()->back();
    }
}